package com.etang.homeproject2.slice;

import com.etang.homeproject2.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class WeleComeAbilitySlice extends AbilitySlice {
    private Text tv_login_helloworld;
    private int number = 0;


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_welecome);
        initView();
        show_login_text();
    }

    private void show_login_text() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (number < 6) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    number++;
                    getUITaskDispatcher().asyncDispatch(new Runnable() {
                        @Override
                        public void run() {
                            if (number == 1) {
                                tv_login_helloworld.setText("你好，世界");
                            }
                            if (number == 2) {
                                tv_login_helloworld.setText("你好，鸿蒙");
                            }
                            if (number == 3) {
                                tv_login_helloworld.setText("正在加载，请稍后...");
                            }
                            if (number == 5) {
                                tv_login_helloworld.setVisibility(Component.INVISIBLE);
                                WeleComeAbilitySlice.super.setUIContent(ResourceTable.Layout_ability_welecome_2);
                            }
                        }
                    });
                }
            }
        }).start();
    }

    private void initView() {
        tv_login_helloworld = (Text) findComponentById(ResourceTable.Id_tv_login_helloworld);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
